package com.xiaoma.base.extend;

import java.lang.reflect.Constructor;
import java.util.EnumMap;
import java.util.Map;

public class HandlerFactory {

    public static final Map<HandlerEnum,AbstractHandler> handlers = new EnumMap<>(HandlerEnum.class);


    public static  AbstractHandler getHandler(HandlerEnum type) throws Exception {
        AbstractHandler handler = handlers.get(type);
        if(handler != null){
            return handler;
        }
        Constructor<? extends AbstractHandler> constructor= type.getHandler().getConstructor();
        handler=constructor.newInstance();
        handlers.put(type,handler);
        return handler;
    }
    
}
